package com.example.mapper;

import com.example.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Description:
 * User: 阿宾
 * Date: 2025-04-16
 * Time: 13:46
 */
@Mapper
public interface UserInfoMapper {
    /**
     * 查询所有用户
     * @return
     */
    @Select("select * from user_info")
    List<UserInfo> queryAllUser();

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user_info where id = #{id}")
    UserInfo queryId(Integer id);

    @Select("select * from user_info where age = #{age} and delete_flag = #{deleteflag}")
    UserInfo queryId1(@Param("age") Integer Age, Integer deleteflag);

    /**
     * 增加用户
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info(username,password,age,gender) "+
            "values (#{username},#{password},#{age},#{gender})")
    Integer insertUser(UserInfo userInfo);


    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info(username,password,age,gender) "+
            "values (#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender})")
    Integer insertUser1(@Param("userInfo") UserInfo userInfo);


    /*
     * 删除指定id的用户
     * @param id
     */
    @Delete("delete from user_info where id = #{id}")
    Integer delete(Integer id);

    /**
     * 更新用户信息
     * @param userInfo
     * @return
     */

    @Update("update user_info set username = #{username} where id = #{id}")
    Integer update(UserInfo userInfo);

    @Select("select id,username,password,age,gender,phone,delete_flag as deleteflag,create_time as createtime" +
            ",update_time as updatetime from user_info")
    List<UserInfo> select();


    /**
     * 结果映射方式
     * @return
     */

    @Results(id = "resultmap",value = {
            @Result(column = "delete_flag",property = "deleteflag"),
            @Result(column = "create_time",property = "createtime"),
            @Result(column = "update_time",property = "updatetime")
    })
    @Select("select * from user_info")
    List<UserInfo> select1();


    @ResultMap("resultmap")
    @Select("select * from user_info where id = #{id}")
    UserInfo select2(Integer id);



    @Select("select * from user_info where id = #{id}")
    UserInfo select3(Integer id);


    @Select("select * from user_info where delete_flag = #{deleteflag}")
    List<UserInfo> getUserInfoByDeleteFlag(Integer deleteflag);

    @Select("select * from user_info where delete_flag = ${deleteflag}")
    List<UserInfo> getUserInfoByDeleteFlag1(Integer deleteflag);


    @Select("select * from user_info where username = #{username}")
    List<UserInfo> getUserInfoByUserName(String username);

    @Select("select * from user_info where username = '${username}'")
    List<UserInfo> getUserInfoByUserName1(String username);



    @Select("select * from user_info order by id #{sort}")
    List<UserInfo> getUserInfoByIdSort(String sort);

    @Select("select * from user_info order by id ${sort}")
    List<UserInfo> getUserInfoByIdSort1(String sort);


    @Select("select * from user_info where username like '%${like}%'")
    List<UserInfo> getUserInfoByUserNameLike(String like);

    @Select("select * from user_info where username like concat('%',#{like},'%')")
    List<UserInfo> getUserInfoByUserNameLike1(String like);
}
